home *** CD-ROM | disk | FTP | other *** search
/ Maclife 42 / MACLIFE42.ISO.7z / MACLIFE42.ISO / FreeWare200 / 圧縮伸張⁄コード / MacGzip / MacGzip 1.1.2 Source.sea / MacGzip 1.1.2 Source / Mac / MacAE.c < prev    next >
Text File  |  1997-04-01  |  4KB  |  173 lines

  1. /*
  2.  * MacAE.c, (C) SPDsoft
  3.  * 1994, MacGzip 0.3
  4.  * August 18, 1995; 1.0
  5.  */
  6.  
  7. #include <AppleEvents.h>
  8. #include "MacAE.h"
  9. #include "FileTypes.h"
  10. #include "Globals.h"
  11. #include "Work.h"
  12.  
  13. /******************************************************************************/
  14. /* key codes
  15.  *
  16.  * I get these values from the inspection of return values  of GetKeys
  17.  * I have no idea about if they are defined somewhere...
  18.  * If you are interested, you can get 'GetKeys' Application from
  19.  * ftp://ivo.cps.unizar.es/SPDsoft/
  20.  */
  21.  
  22. #define IsOptKey(a)        a[1] & 0x00000004    /* 0x3a in keyboard layout (?) */
  23. #define IsShiftKey(a)    a[1] & 0x00000001    /* 0x38 in keyboard layout (?) */
  24. #define IsCtrlKey(a)    a[1] & 0x00000008
  25.  
  26. #define IsAKey(a)        a[0] & 0x01000000    /* 0x00 in keyboard layout (?) */
  27. #define IsBKey(a)        a[0] & 0x00080000    /* 0x0b in keyboard layout (?) */
  28. #define IsMKey(a)        a[1] & 0x00400000    /* 0x2e in keyboard layout (?) */
  29.  
  30.  
  31. /******************************************************************************/
  32.  
  33. #define kDropSoundID    129
  34.  
  35. static OSErr MyGotRequiredParams (AppleEvent *theAppleEvent);
  36.  
  37. /******************************************************************************/
  38. /* Standard AE */
  39.  
  40. pascal OSErr  MyHandleODoc (    AppleEvent *theAppleEvent,
  41.                                 AppleEvent* reply,
  42.                                 long handlerRefCon    )
  43. {
  44. #pragma unused(reply)
  45. #pragma unused(handlerRefCon)
  46.  
  47.     FSSpec        myFSS;
  48.     AEDescList    docList;
  49.     OSErr        AEerr, res;
  50.     long        index,
  51.                 itemsInList;
  52.     Size        actualSize;
  53.     AEKeyword    keywd;
  54.     DescType    returnedType;
  55.     KeyMap        theKeys;
  56.  
  57.     AEerr = AEGetParamDesc (theAppleEvent, keyDirectObject, typeAEList, &docList);
  58.     if (AEerr)
  59.             return AEerr;
  60.  
  61.     AEerr = MyGotRequiredParams (theAppleEvent);
  62.     if (AEerr)
  63.             return AEerr;
  64.  
  65.     AEerr = AECountItems (&docList, &itemsInList);
  66.  
  67.     GetKeys(theKeys);
  68.     
  69.     if ( gPrefs.Misc.BeepWhenDone )
  70.         MyBeep( kDropSoundID );
  71.         
  72.     for (index = 1, res=0; index <= itemsInList; index++)
  73.     {
  74.             AEerr = AEGetNthPtr (&docList, index, typeFSS, &keywd,
  75.                     &returnedType, (Ptr) &myFSS, sizeof(myFSS), &actualSize);
  76.             if (AEerr)
  77.                     return AEerr;
  78.  
  79.             res = new_work(
  80.                         IsAKey (theKeys) ?
  81.                                             kAppKeyASCII :
  82.                         IsBKey (theKeys) ?
  83.                                             kAppKeyBin :
  84.                         IsMKey (theKeys) ?
  85.                                             kAppKeyMBin :
  86.                         0,
  87.                         
  88.                         gPrefs.Misc.Keys ?
  89.                         (
  90.                             IsOptKey( theKeys ) ?
  91.                                             kMisc_gzip :
  92.                             IsShiftKey( theKeys ) ?
  93.                                             kMisc_gunzip :
  94.                             kMisc_auto
  95.                                             
  96.                         )
  97.                         :
  98.                         kMisc_auto,
  99.                         gPrefs.Misc.Keys && IsCtrlKey(theKeys),
  100.                         &myFSS );
  101.                         
  102.     }
  103.  
  104.     AEerr = AEDisposeDesc (&docList);
  105.     
  106.     return res;
  107. }
  108.  
  109. pascal OSErr  MyHandlePDoc (    AppleEvent *theAppleEvent,
  110.                                 AppleEvent *reply,
  111.                                 long handlerRefCon    )
  112. {
  113. #pragma unused(theAppleEvent)
  114. #pragma unused(reply)
  115. #pragma unused(handlerRefCon)
  116.     /* can't print by now */
  117.     return ( errAEEventNotHandled );
  118. }
  119.  
  120. pascal OSErr  MyHandleOApp (    AppleEvent *theAppleEvent,
  121.                                 AppleEvent *reply,
  122.                                 long handlerRefCon    )
  123. {
  124. #pragma unused(reply)
  125. #pragma unused(handlerRefCon)
  126.  
  127.     gApp.StartupFiles = FALSE;
  128.             
  129.     return ( MyGotRequiredParams (theAppleEvent) );
  130. }
  131.  
  132.  
  133. pascal    OSErr    MyHandleQuit (    AppleEvent *theAppleEvent,
  134.                                 AppleEvent *reply,
  135.                                 long handlerRefcon    )
  136. {
  137. #pragma unused(reply)
  138. #pragma unused(handlerRefcon)
  139.     OSErr            AEerr;
  140.     
  141.     if (noErr != (AEerr = MyGotRequiredParams(theAppleEvent)))
  142.     {
  143.         // an error occurred:  do the necessary error handling
  144.         return    AEerr;
  145.     }
  146.     
  147.     /* we should cleanup here */
  148.     
  149.     gApp.quit = TRUE;
  150.     
  151.     return ( noErr );
  152. }
  153.  
  154. /******************************************************************************/
  155. static OSErr MyGotRequiredParams (AppleEvent *theAppleEvent)
  156. {
  157.     DescType    returnedType;
  158.     Size        actualSize;
  159.     OSErr        myerr;
  160.  
  161.     myerr = AEGetAttributePtr (        theAppleEvent, keyMissedKeywordAttr,
  162.                                     typeWildCard, &returnedType, nil, 0,
  163.                                     &actualSize
  164.                                 );
  165.                                 
  166.     if (myerr == errAEDescNotFound)        // you got all the required parameters
  167.             return noErr;
  168.     else if (!myerr)                    // you missed a required parameter
  169.             return errAEEventNotHandled;
  170.     else                                // the call to AEGetAttributePtr failed
  171.             return myerr;
  172. }
  173.